const Controller=qguan("Controller")

/**
 * web端依赖
 */
@Controller("/reactLib")
export default  class ReactLibCtrl{
    constructor(){
        let _this=this;
        let root=  qguan("root");
        let Jsr=  qguan("jsr");

        let data=root.findData("webReactServer.jsr")

        data.then(   (data1)=>{
            let jsr =new Jsr();
            jsr.loadData(data1)
           _this.jsr=jsr;
        } )
    }
    //用户登录
    @Controller("/")
    find(req,res,url){

        let _this=this;
        let _name= url.pathname.substring(url.pathname.lastIndexOf("/")+1);
        res.setHeader("Content-Type", "application/x-javascript");
        res.setHeader("Content-Disposition", "attachment; filename="+_name);
        res.setHeader("Access-Control-Allow-Origin", "*");



        try{
            //  this.userService.add();
            if(_name!="admin.js"){
                let code=  _this.jsr.findFileByRegular(null,null,_name);
                if(code){
                    debugger;
                    let tes1=new TextDecoder();
                    let buff=new Uint8Array(code);
                    let txt= tes1.decode(buff);
                    res.write(txt)
                    res.end();
                }else {
                    res.write(JSON.stringify({
                        message: '异常'
                    }))
                    res.end();
                }

            }else {
                let admin=qguan("admin");
                admin.run(req,res,url)
            }

            res.end();

        }catch (e) {
            res.write(JSON.stringify({
                message: '异常'
            }))
            res.end();
            return;
        }

    }


}



